<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Transaksi - Faktur Penjualan</title>
<link href="<?php echo base_url(); ?>assets/css/style-trx.css" rel="stylesheet" type="text/css"/>
	<link rel="stylesheet" href="<?php echo base_url()?>assets/jqueryui/themes/jquery.ui.all.css">
</head>
<body style="background:#CCC; font-size:70%;">
<center>
<div class="kanvas">
<div class="trx-title">
	<a href="<?php echo base_url()?>index.php/home">Home</a>
    &nbsp;&raquo;&nbsp;Transaksi&nbsp;&raquo;&nbsp;Penjualan&nbsp;&raquo;&nbsp;Status SO&nbsp;&raquo;&nbsp;Non Tender&nbsp;&raquo;&nbsp;Bukti Keluar Barang
</div>
<div class="trx">
<table width="100%" cellpadding="0" cellspacing="0" style="border:#000 1px solid;">
	<tr height="25">
    	<td width="10%" class="trx-title-table"><strong>No BKB</strong>&nbsp;&nbsp;</td>
    	<td width="90%" class="trx-isi-table">&nbsp;&nbsp;<?php echo $nobkb;?></td>
    </tr>
	<tr height="25">
    	<td width="10%" class="trx-title-table"><strong>Tanggal</strong>&nbsp;&nbsp;</td>
    	<td width="90%" class="trx-isi-table">&nbsp;&nbsp;<?php echo $tanggal;?></td>
    </tr>
	<tr height="25">
    	<td width="10%" class="trx-title-table"><strong>No Pesanan</strong>&nbsp;&nbsp;</td>
    	<td width="90%" class="trx-isi-table">&nbsp;&nbsp;<?php echo $soid;?></td>
    </tr>
	<tr height="25">
    	<td width="10%" class="trx-title-table"><strong>Kepada</strong>&nbsp;&nbsp;</td>
    	<td width="90%" class="trx-isi-table">&nbsp;&nbsp;<?php echo $row->kepada;?></td>
    </tr>
	<tr height="25">
    	<td width="10%" class="trx-title-tables"><strong>Untuk</strong>&nbsp;&nbsp;</td>
    	<td width="90%" class="trx-isi-tables">&nbsp;&nbsp;<?php echo $row->untuk;?></td>
    </tr>
</table>
<br />
<table width="100%" cellpadding="0" cellspacing="0" class="trx-table">
<tr height="25">
	<td width="3%" align="center" class="border-bawah">No</td>
	<td width="20%" align="center" class="border-bawah">Nama Barang</td>
	<td width="13%" align="center" class="border-bawah">Pabrik</td>
	<td width="5%" align="center" class="border-bawah">Qty</td>
	<td width="7%" align="center" class="border-bawah">Satuan</td>
	<td width="25%" align="center" class="border-bawah">Keterangan</td>
	<td width="6%" align="center" class="border-bawah">Qty</td>
	<td width="13%" align="center" class="border-bawah">Batch</td>
	<td width="8%" align="center" class="border-bawah"></td>
</tr>
<?php
if(!empty($daftar_so)){

	$nmr = 1;
	foreach($daftar_so as $row){
?>
<tr height="25">
	<td align="center"><?php echo $nmr;?></td>
	<td>&nbsp;<?php echo $row->nama;?></td>
	<td>&nbsp;<?php echo $row->nama_pabrik;?></td>
	<td align="center"><?php echo $row->qty;?></td>
	<td align="center"><?php echo $nmr;?></td>
	<td>&nbsp;<?php echo $row->keterangan;?></td>
	<td align="center"><?php echo $row->qty;?></td>
	<td align="center"><?php echo $row->nobatch;?></td>
	<td align="center">
    	<img onclick="proses('<?php echo $nobkb;?>','<?php echo $soid;?>','<?php echo $row->prokode;?>')" src="<?php echo base_url();?>assets/img/edit.png" width="18"/>
        <img onclick="return hapus('<?php echo $row->nama;?>')" src="<?php echo base_url();?>assets/img/delete.png" width="18"/>
    </td>
</tr>
<?php
	$nmr++;
	}	
}
?>
<tr>
</tr>
</table>
</div>
</center>
</body>
</html>
	<script src="<?php echo base_url()?>assets/jqueryui/jquery-1.9.1.js"></script>
    <script src="<?php echo base_url()?>assets/jqueryui/ui/jquery.ui.core.js"></script>
    <script src="<?php echo base_url()?>assets/jqueryui/ui/jquery.ui.widget.js"></script>
    <script src="<?php echo base_url()?>assets/jqueryui/ui/jquery.ui.position.js"></script>
    <script src="<?php echo base_url()?>assets/jqueryui/ui/jquery.ui.menu.js"></script>
    <script src="<?php echo base_url()?>assets/jqueryui/ui/jquery.ui.autocomplete.js"></script>
    <script src="<?php echo base_url()?>assets/jqueryui/ui/jquery.ui.datepicker.js"></script>
   	<script src="<?php echo base_url()?>assets/jqueryui/ui/jquery.ui.tooltip.js"></script>
    <script>
	$(function() {
		$( document ).tooltip({
			position: {
				my: "center bottom-20",
				at: "center top",
				using: function( position, feedback ) {
					$( this ).css( position );
					$( "<div>" )
						.addClass( "arrow" )
						.addClass( feedback.vertical )
						.addClass( feedback.horizontal )
						.appendTo( this );
				}
			}
		});
	});

	var site = "<?php echo site_url();?>";
	$(function() {
		$("#prokode").autocomplete({
		source: site+"/transaksi/search/barang",	
		minLength: 1,
		select: function(event, ui) {
			var hasil = ui.item.value.split('-');
			$('#prokode').val(hasil[0]);
			$('#nama').val(hasil[1]);
			$('#qty').val('1');
			$('#harga').val(hasil[2]);
			$('#satuan').val(hasil[3]);
			$('#total').val(hasil[2]*1);
			return false;
		}
		});
	});

	var site = "<?php echo site_url();?>";
	$(function() {
		$("#nama1").autocomplete({
		source: site+"/transaksi/search/pelanggan",	
		minLength: 1,
		select: function(event, ui) {
			var hasil = ui.item.value.split('-');
			$('#kdcus1').val(hasil[0]);
			$('#nama1').val(hasil[1]);
			$('#alamat1').val(hasil[2]);
			$('#kota1').val(hasil[3]);
			$('#tlp1').val(hasil[4]);
			return false;
		}
		});
	});

	var site = "<?php echo site_url();?>";
	$(function() {
		$("#nama2").autocomplete({
		source: site+"/transaksi/search/pelanggan",	
		minLength: 1,
		select: function(event, ui) {
			var hasil = ui.item.value.split('-');
			$('#kdcus2').val(hasil[0]);
			$('#nama2').val(hasil[1]);
			$('#alamat2').val(hasil[2]);
			$('#kota2').val(hasil[3]);
			$('#tlp2').val(hasil[4]);
			return false;
		}
		});
	});

	var site = "<?php echo site_url();?>";
	$(function() {
		$("#nama_sales").autocomplete({
		source: site+"/transaksi/search/sales",	
		minLength: 1,
		select: function(event, ui) {
			var hasil = ui.item.value.split('-');
			$('#sales_id').val(hasil[0]);
			$('#nama_sales').val(hasil[1]);
			$('#alamat3').val(hasil[2]);
			$('#kota3').val(hasil[3]);
			$('#tlp3').val(hasil[4]);
			return false;
		}
		});
	});
		
function formatNumber (obj, decimal) {
	anynum=eval(obj.value);
	divider =10;
	switch(decimal){
		case 0:
			divider =1;
			break;
		case 1:
			divider =10;
			break;
		case 2:
			divider =100;
			break;
		default:  	 //for 3 decimal places
			divider =1000;
	}
	workNum=Math.abs((Math.round(anynum*divider)/divider));
	workStr=""+workNum
	if (workStr.indexOf(".")==-1){workStr+="."}
	dStr=workStr.substr(0,workStr.indexOf("."));dNum=dStr-0
	pStr=workStr.substr(workStr.indexOf("."))
	while (pStr.length-1< decimal){pStr+="0"}
	if(pStr =='.') pStr ='';
	//--- Adds a comma in the thousands place.    
	if (dNum>=1000) {
		dLen=dStr.length
		dStr=parseInt(""+(dNum/1000))+"."+dStr.substring(dLen-3,dLen)
	}
	//-- Adds a comma in the millions place.
	if (dNum>=1000000) {
		dLen=dStr.length
		dStr=parseInt(""+(dNum/1000000))+"."+dStr.substring(dLen-7,dLen)
	}
	retval = dStr + pStr
	//-- Put numbers in parentheses if negative.
	if (anynum<0) {retval="("+retval+")";}
	//retval =  "$"+retval
	obj.value = retval;
}

function format_harga() {
  var harga = document.f_so.harga.value;
  harga = harga.replace(/[^0-9.]/g,"");
  harga = harga.replace(".","");
  harga = harga.replace(".","");
  if(harga.length == 0) harga = "0";	

  var qty = document.f_so.qty.value;
  qty = qty.replace(/[^0-9.]/g,"");
  qty = qty.replace(".","");
  qty = qty.replace(".","");
  if(qty.length == 0) qty = "0";	
  
  var total = harga * qty;

  if(qty.length > 0) {
    if(!isNaN(qty)) {
      document.f_so.harga.value = harga;
      document.f_so.qty.value = qty;
      document.f_so.total.value = total;
      formatNumber(document.f_so.harga,0);
      formatNumber(document.f_so.qty,0);
      formatNumber(document.f_so.total,0);
     }	
  } else { document.f_so.qty.value = "0"; }			

}

function format_qty() {
  var harga = document.f_so.harga.value;
  if(harga.length == 0) harga = "0";	

  var qty = document.f_so.qty.value;
  qty = qty.replace(/[^0-9.]/g,"");
  qty = qty.replace(".","");
  qty = qty.replace(".","");
  if(qty.length == 0) qty = "0";	
  
  var total = parseFloat(harga) * qty;

  if(qty.length > 0) {
    if(!isNaN(qty)) {
      document.f_so.qty.value = qty;
      document.f_so.total.value = total;
      formatNumber(document.f_so.qty,0);
      formatNumber(document.f_so.total,1);
     }	
  } else { document.f_so.qty.value = "0"; }			

}

function format_disc() {
  var harga = document.f_so.harga.value;
  harga = harga.replace(/[^0-9.]/g,"");
  harga = harga.replace(".","");
  harga = harga.replace(".","");
  if(harga.length == 0) harga = "0";	

  var qty = document.f_so.qty.value;
  qty = qty.replace(/[^0-9.]/g,"");
  qty = qty.replace(".","");
  qty = qty.replace(".","");
  if(qty.length == 0) qty = "0";	

  var disc = document.f_so.disc.value;
  if(disc.length == 0) disc = "0";
  
  var total = harga * qty * ( 100 - disc)/100;

  if(qty.length > 0) {
    if(!isNaN(qty)) {
      document.f_so.qty.value   = qty;
      document.f_so.total.value = total;
      document.f_so.disc.value  = disc;
      formatNumber(document.f_so.qty,0);
      formatNumber(document.f_so.total,0);
     }	
  } else { document.f_so.qty.value = "0"; }			

}

    function hapus(brg){
        var agree = confirm("Anda Yakin Ingin Menghapus " +  brg  + "?");
        if(agree){
            return true;
        }else{
            return false;
        }
    }

$(function () {
  $("#phg").change(function () {
	//var prokode = document.f_so.prokode.value;
    //$("#harga").load('<?php echo site_url()?>/transaksi/sales_order/pilih_harga?phg=' + $(this).val()+ '&prokode='+prokode);
    $.get('<?php echo site_url()?>/transaksi/sales_order/pilih_harga',{ 
	        phg:$(this).val(),
	        prokode: document.f_so.prokode.value
        } ,function(data) {
            document.f_so.harga.value = data;
            var qty   = document.f_so.qty.value;
            var harga = document.f_so.harga.value;
			var disc = document.f_so.disc.value;            
            
            var total = harga * qty * ( 100 - disc)/100;
            
            document.f_so.total.value = total;
    });
  });
});


	function proses(x,y,z){
		window.open('<?php echo site_url();?>/transaksi/sales_order_out/proses?nobkb='+x+'&soid='+y+'&prokode='+z,'destination','toolbar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=no,copyhistory=no,width=400,height=280,left=450,top=100');
	}
	
<?php
	if(!empty($alert)){
	 	echo "alert('$alert');";
	}
?>
</script>    
